package com.maxmlr.music.controller;

import com.maxmlr.music.model.Result;
import com.maxmlr.music.model.Singer;
import com.maxmlr.music.model.User;
import com.maxmlr.music.service.SingerService;
import com.maxmlr.music.util.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;



/**
 * 歌手控制层
 * @author maxiao
 *
 */
@Controller
@RequestMapping("/singer")
public class SingerController extends FathController {
	
	@Autowired
	private SingerService singerService;
	
	/**
	 * 查看歌手信息
	 * 
	 * @param singer_id
	 * @return
	 */
	@RequestMapping("/tosinger.do")
	public String tosinger(Integer singer_id, Model model, HttpSession session) {
		Map<String, Object> map = singerService.fingSingerById(singer_id);
		User user = (User) session.getAttribute(USER);
		if (user != null) {
			model.addAttribute(USER, user);
		}
		if (TRUE.equals(Tool.dellNull(map.get(FLAG)))) {
			model.addAttribute("singer", (Singer) map.get(RET));
			return "page/singer";
		}
		return "page/mainPage";
	}
	
	/**
	 * 加载主页面歌手
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping("/addSinger.do")
	public Result addSinger(Integer page) {
		Map<String, Object> map = singerService.findSinger(page);
		Result re = new Result();
		if (TRUE.equals(Tool.dellNull(map.get(FLAG)))) {
			re.setData((List<Singer>) map.get(RET));
		}
		return re;
	}
}
